 <template>
<div class="wrapper">
  <div class="search">
    <div
      class="search_back iconfont"
      @click="handleBackClick">&#xe662;</div>
    <div class="search_content">
      <span class="search_content_icon iconfont">&#xe648;</span>
      <input class="search_content_input" placeholder="请输入商品名称" type="text">
    </div>
  </div>
  <ShopInfo :item="item" :hideBorder="true" v-show="item.imgUrl"></ShopInfo>
  <Content :shopName="item.name"></Content>
  <Cart></Cart>
</div>
</template>

<script>
import { useRouter, useRoute } from 'vue-router'
import { reactive, toRefs } from 'vue'
import { get } from '@/utils/request'
import ShopInfo from '@/components/ShopInfo'
import Content from './Content'
import Cart from './Cart'
// 获取当前商铺信息
const useShopInfoEffect = () => {
  const route = useRoute()
  const data = reactive({ item: {} })
  const getItemData = async () => {
    const result = await get(`/api/shop/${route.params.id}`)
    if (result?.errno === 0 && result?.data) {
      data.item = result.data
    }
  }
  const { item } = toRefs(data)
  return { item, getItemData }
}
// 回退按钮
const useBackEffect = () => {
  const router = useRouter()
  const handleBackClick = () => {
    router.back()
  }
  return { handleBackClick }
}
export default {
  name: 'Shop',
  components: { ShopInfo, Content, Cart },
  setup (props) {
    const { getItemData, item } = useShopInfoEffect()
    const { handleBackClick } = useBackEffect()
    getItemData()
    return { item, handleBackClick }
  }
}
</script>
<style lang="scss" scoped>
@import '@/style/viriables.scss';
.wrapper {
  padding: 0 0.18rem;
}
.search{
  display: flex;
  margin: .14rem 0 .04rem 0;
  line-height: .32rem;
  &_back{
    width: .3rem;
    font-size: .28rem;
    color: #b6b6b6;
  }
  &_content{
    display: flex;
    flex: 1;
    background: $search-bgColor;
    border-radius: .16rem;
    &_icon{
      width: .44rem;
      text-align: center;
      color: $search-fontColor;
    }
    &_input{
      display: block;
      border: none;
      background: none;
      outline: none;
      height: .32rem;
      width: 100%;
      padding-right: .2rem;
      color: $content-fontcolor;
      font-size: .14rem;
      &::placeholder{
        color: $content-fontcolor;
      }
    }
  }
}
</style>
